var Login = function () {

	var handleLogin = function() {
		$('.login-form').validate({
	            errorElement: 'span', //default input error message container
	            errorClass: 'help-block', // default input error message class
	            focusInvalid: false, // do not focus the last invalid input
	            rules: {
	                loginName: {
	                    required: true
	                },
	                loginPwd: {
	                    required: true
	                },
                    verify: {
	                    required: true,
	                    remote:remoteUrl
	                },
	                remember: {
	                    required: false
	                }
	            },

	            messages: {
	                loginName: {
	                    required: "用户名不能为空。"
	                },
	                loginPwd: {
	                    required: "密码不能为空。"
	                },
                    verify: {
	                    required: "验证码不能为空。",
	                    remote:"验证码错误！"
	                }
	            },

	            /* invalidHandler: function (event, validator) { //display error alert on form submit
	                $('.alert-danger', $('.login-form')).show();
	            }, */

	            highlight: function (element) { // hightlight error inputs
	                $(element)
	                    .closest('.form-group').addClass('has-error'); // set error class to the control group
	            },

	            success: function (label) {
	                label.closest('.form-group').removeClass('has-error');
	                label.remove();
	            },

	            errorPlacement: function (error, element) {
	                error.insertAfter(element.closest('.input-icon'));
	            },

	            submitHandler: function (form) {
					//layer.msg('正在登录...');
				    $.ajax({  
						type : "post",  
						dataType : "json",  
						data: $(".login-form").serialize(),  
						success : function(data) {
							if(data.status=='1'){
								layer.msg(data.info, 
									{icon: 1,time: 2000},
									function(){
				    					location.href=data.url;
									}
								);   	
							}else{
								layer.msg(data.info, 
									{icon: 2,time: 2000},
									function(){
				    					$('#loginname').focus();
				    				}
				    			);   
								return;
							}
						}  
				    });           
	            }
	        });

	        $('.login-form input').keypress(function (e) {
	            if (e.which == 13) {
	                if ($('.login-form').validate().form()) {
	                    $('.login-form').submit();
	                }
	                return false;
	            }
	        });
	}

	
    return {
        //main function to initiate the module
        init: function () {
            handleLogin();
	       	$.backstretch([
		        Public+"/Admin/img/bg/1.jpg",
		        Public+"/Admin/img/bg/2.jpg",
		        Public+"/Admin/img/bg/3.jpg",
		        Public+"/Admin/img/bg/4.jpg"
		        ], {
		          fade: 1000,
		          duration: 8000
		    });
        }

    };

}();